package kr.hkit.powerjava.chapter14.programming;

import java.awt.BorderLayout;
import java.awt.EventQueue;

import javax.swing.JFrame;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.BoxLayout;
import javax.swing.JLabel;
import javax.swing.JTextField;
import javax.swing.JButton;
import javax.swing.SwingConstants;
import java.awt.FlowLayout;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;

public class IFrame extends JFrame implements ActionListener {

	private JPanel contentPane;
	private JPanel panel;
	private JPanel panel_1;
	private JPanel panel_2;
	private JLabel lblNewLabel;
	private JTextField txt1;
	private JLabel lblNewLabel_1;
	private JTextField txt2;
	private JButton btnNewButton;
	private JPanel panel_3;
	private JTextField txt3;

	/**
	 * Launch the application.
	 */
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					IFrame frame = new IFrame();
					frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();
				}
			}
		});
	}

	/**
	 * Create the frame.
	 */
	public IFrame() {
		initialize();
	}
	private void initialize() {
		setTitle("이자 계산기");
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setBounds(100, 100, 294, 169);
		contentPane = new JPanel();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		setContentPane(contentPane);
		contentPane.setLayout(new BoxLayout(contentPane, BoxLayout.Y_AXIS));
		
		panel = new JPanel();
		contentPane.add(panel);
		
		lblNewLabel = new JLabel("원금을 입력하시오");
		lblNewLabel.setHorizontalAlignment(SwingConstants.LEFT);
		panel.add(lblNewLabel);
		
		txt1 = new JTextField();
		panel.add(txt1);
		txt1.setColumns(10);
		
		panel_1 = new JPanel();
		contentPane.add(panel_1);
		
		lblNewLabel_1 = new JLabel("이율을 입력하시오");
		panel_1.add(lblNewLabel_1);
		
		txt2 = new JTextField();
		panel_1.add(txt2);
		txt2.setColumns(10);
		
		panel_2 = new JPanel();
		contentPane.add(panel_2);
		panel_2.setLayout(new FlowLayout(FlowLayout.CENTER, 5, 5));
		
		btnNewButton = new JButton("변환");
		btnNewButton.addActionListener(this);
		panel_2.add(btnNewButton);
		
		panel_3 = new JPanel();
		contentPane.add(panel_3);
		
		txt3 = new JTextField();
		txt3.setColumns(20);
		panel_3.add(txt3);
	}

	public String getTxt1() {
		return txt1.getText();
	}

	public void setTxt1(String text) {
		txt1.setText(text);;
	}

	public String getTxt2() {
		return txt2.getText();
	}

	public void setTxt2(String text) {
		txt2.setText(text);;
	}

	public String getTxt3() {
		return txt3.getText();
	}

	public void setTxt3(String text) {
		txt3.setText(text);;
	}

	public void actionPerformed(ActionEvent e) {
		int a = Integer.parseInt(getTxt1().trim());
		double b = Double.parseDouble(getTxt2().trim());
		txt3.setText("이자는 연" + (int)(a * b / 100) + "만원 입니다.");
	}
}
